package
{
	import flash.display.NativeWindow;
	import flash.display.NativeWindowInitOptions;
	import flash.display.NativeWindowSystemChrome;
	import flash.display.NativeWindowType;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.text.TextField;

	public class TestAir extends Sprite
	{
		public function TestAir()
		{
			var back:Shape = new Shape();
			
			back.graphics.beginFill(0xff0000,0.5);
			back.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
			back.graphics.endFill();
			
//			addChild(back);
			
			
			stage.addEventListener(MouseEvent.RIGHT_CLICK, function(event:Event):void
			{
				stage.nativeWindow.close();
			});

			stage.nativeWindow.x = 0;
			stage.nativeWindow.y = 0;

			stage.nativeWindow.activate();
			
			stage.addEventListener(MouseEvent.MOUSE_DOWN, function(event:Event):void
			{
				stage.nativeWindow.startMove();
			});

			
			
			var btn:TextField = new TextField();

			btn.width = 100;

			btn.height = 20;

			btn.text = "asdfsf";

			addChild(btn);

			btn.addEventListener(MouseEvent.CLICK, function(event:Event):void
			{
				var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
				windowOptions.systemChrome = NativeWindowSystemChrome.NONE;
				windowOptions.type = NativeWindowType.NORMAL;

				var newWindow:NativeWindow = new NativeWindow(windowOptions);
				newWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
				newWindow.stage.align = StageAlign.TOP_LEFT;
				newWindow.bounds = new Rectangle(stage.nativeWindow.x, stage.nativeWindow.y + stage.nativeWindow.height, 200, 200);

				newWindow.activate();

				var back:Shape = new Shape();
				
				back.graphics.beginFill(Math.random()*0xffffff,0.5);
				back.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
				back.graphics.endFill();
				
				newWindow.stage.addChild(back);
				
				trace(newWindow.globalToScreen(new Point(0,0)));
			});
		}
	}
}
